$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/book/book/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
            bookName:	{
                required : true,
                minlength : 1,
				maxlength : 15
			},
            author : {
				require : true,
				minlength : 1
			},
            press : {
                require : true,
                minlength : 4
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			},
            bookName:	{
                required : icon + "请输入图书名称",
                minlength : icon + "图书名称不能为空",
                maxlength : icon + "图书名称不能超过15个字"
            },
            author : {
                required : icon + "请输入作者",
                minlength : icon + "作者名必须一个字符以上"
            },
            press : {
                require : icon + "请输入出版社",
                minlength : icon + "出版社必须四个字符以上"
            }
		}
	})
}